new Vue({
    el:"#app",
    data:{
        list:[],
        count_rows: 0, //总数
        page: 0,//当前页
        pageSize: 6, //每页条数
        totalPage: 0,//总页数
    },
    methods:{
        //1.获取列表
        async getList(){
            let res = await axios.get("/users/list");
            let {data}=res;

            // console.log(data)

            this.list = data.data.list||[];
            
            let ret = data.data||[];
            this.count_rows = ret.count_rows;
            this.page = ret.page;
            this.pageSize = ret.pageSize;
            this.totalPage = ret.totalPage;
        },
        //2.分页
        async currPage(n) {
            this.page = n;
            let { data } = await axios.get("/users/list?page=" + n);
            // console.log(data)
            //重新渲染
            if (data.code == 0) {
                var ret = data.data || [];//数据
                this.list = ret.list || []

                this.count_rows = ret.count_rows;
                this.page = ret.page;
                this.pageSize = ret.pageSize;
                this.totalPage = ret.totalPage;
            }
        },
        //3.导出excel
        excel() {
            window.location.href = "/users/export";
        },
        //4.删除
        async deleteStudent(id){
            if(confirm("确定删除吗?")){
                 // alert(id)
                let ret = await axios.delete("/users/delete?id="+id);
                let {data:data} = ret;
                // console.log(data)
                if(data.code == 0){
                    // console.log("del ok")
                    this.getList()//重新获取数据
                }
            }
        }
    },
    created(){
        this.getList()
    },
    filters:{
        formateDate(val){
            return dayjs.unix(val).format("MM-DD HH:mm:ss")
            // return 1;
        },
        formateCollage(val){
            var value="";
            switch(val){
                case 1:
                    value = '专科'
                    break;
                case 2:
                    value = '本科'
                    break;
                case 3:
                    value = '研究生'
                    break;
                default:
                    value = '-';
            }
            return value;
        },
        formateFresh(val){
            var value="";
            switch(val){
                case 1:
                    value = '是'
                    break;
                case 0:
                    value = '否'
                    break;
                default:
                    value = '-';
            }
            return value;
        }
        
    }
})